package com.season.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.reason.order.pojo.Order;
import com.season.order.service.OrderService;
import com.season.order.dao.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 陈正果
 * @date 2020/6/30 11:04
 */

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    /**
     * 插入订单
     *
     * @param order 插入订单信息
     * @return 影响行数
     */
    @Override
    public int insertOrder(Order order) {
        return orderMapper.insert(order);
    }

    /**
     * 更新订单
     *
     * @param order 需要更新订单信息
     * @return 影响行数
     */
    @Override
    public int updateOrder(Order order) {
        return orderMapper.updateById(order);
    }

    /**
     * 通过用户名查询
     *
     * @param username 用户名
     * @return Order
     */
    @Override
    public Order findByUsername(String username) {
        Map<String, Object> columnMap = new HashMap<>();
        columnMap.put("username", username);
        return orderMapper.selectByMap(columnMap).get(0);
    }

    /**
     * 通过用户id查询
     *
     * @param id 用户id
     * @return Order
     */
    @Override
    public Order findById(String id) {
        return orderMapper.selectById(id);
    }

}
